Repository navigation
feat(web-function): manage .local companion log group - #105
Conversation
…groups Record design revision 5 for managed .local companion log groups (#104): WebFunctionLogs Create/Use API, LocalLogGroup, THREE_DAYS companion default, explicit revision dependencies, per-resource-type execution-role grants with a synthesis-time Lazy Region (order-independent AddEndpoint), W1/W2 warnings, AlreadyExists guidance, tests, and sandbox check 3.9. Beads: close cdkc-18e.18.1; refine cdkc-18e.18.2-.18.4. Refs #104 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement design revision 5 for issue #104: - WebFunctionLogs.Create gains companionRetention (default THREE_DAYS); Use gains an optional companion log group with literal-name validation. - WebFunctionConstruct creates the .local companion log group (child LocalLogGroup), exposes ILogGroup? LocalLogGroup, and adds revision dependencies on managed log groups. - Companion IAM grants G1 (always) and G2 (conditional) with synthesis-deferred Region widening; warnings W1/W2. - Testing assertions ShouldHaveLogGroup/ShouldHaveCompanionLogGroup/ShouldHaveRevisionDependingOnLogGroups; 36 new tests; regenerated Web Function golden templates. Bead: cdkc-18e.18.2
Apply the independent-review corrections to the revision-5 companion (.local) log group implementation: - D1: rename the new log-group assertion to ShouldHaveWebFunctionLogGroup to avoid a CS0121 clash with the published LambdaFunctionConstructAssertions.ShouldHaveLogGroup; restore the extension call in TestingHelpersTests and add consumer/negative coverage. - D2: add meaningful positive+negative tests for all three new assertions. - D3: make the W2 warning token-safe (name substituted with "this endpoint" when unresolved); add a tokenized-endpoint regression test. - D4: use the uncached Lazy.UncachedString/IStringProducer so G1/G2 reflect the final endpoint set even when the role policy is resolved before AddEndpoint; add early-resolution ordering tests (P11b). - D5: validate the supplied companion name against the underlying CfnLogGroup (via the construct default child) for owned groups, keeping token tolerance. - D6: assert Properties.ServiceConfig.TelemetryConfig in the ServiceDefault test instead of the vacuous Properties.TelemetryConfig. - Strengthen IAM/dependency tests to exact actions and full ARN structure; assert the real revision DependsOn (T8), add a cross-stack owned-group case (T8b) and warning acknowledgement tests. - Record design errata A/B/C in the revision-5 design document (no revision 6). Validation: Release build 0 warnings/0 errors on net8.0-net11.0; 590 tests, 0 failed, 0 skipped on each TFM; coverage line 94.46% / branch 86.28%; Web Function and existing-construct golden templates unchanged.
F1: add explicit companion-name validation regressions (owned owned/imported/tokenized/unnamed). F2: assert specific exception types and messages in companion assertion helper tests. F3: pin the exact consumer-stack revision dependency set in the cross-stack case. F4: make W2 endpoint label readable and token-safe (no doubled 'Endpoint' prefix). F5: correct revision-5 Erratum B wording for Create/Use companion-name derivation.
…ion (#104) Add a read-only verify-log-groups.sh that asserts the companion .local log-group acceptance criteria (existence, retention, delivery, and no unexpected groups) against the live CloudWatch Logs API, sourcing the expected groups/retentions from a new LogGroupExpectations app output. Add two Use-mode logging functions (caller-owned custom centralised group with a supplied execution role, and a supplied companion group) and a non-default Create() companion retention on Blazor so both the managed and Use-mode paths are exercised. Teach destroy.sh to remove the one Lambda-created .local companion that CloudFormation does not own, by exact sandbox-namespaced name only, and extend the offline aws/cdk stubs plus lifecycle scenarios to cover it.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 586486d1e1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # 5b. Verify the companion ".local" log groups and their retention (read-only). Run once right after | ||
| # deploy (pre-traffic) and again with --expect-delivery after real requests. | ||
| SANDBOX_ALLOW_AWS=1 ./verify-log-groups.sh | ||
| SANDBOX_ALLOW_AWS=1 ./verify-log-groups.sh --expect-delivery |
There was a problem hiding this comment.
Invoke the Use-mode workloads before checking log delivery
On a fresh sandbox, this documented sequence does not generate traffic for the new UseLogs and UseCompanion functions: smoke.sh still only reads endpoint URLs and sends requests for Next.js, ASP.NET Core, and Blazor. Consequently, verify-log-groups.sh --expect-delivery, which requires events in all ten groups, fails for the new workloads, and the service-created UseLogs companion may not even exist. Add signed requests to both new endpoints to the smoke harness (and expose their URLs), or include an explicit invocation step before this delivery check.
Useful? React with 👍 / 👎.
| foreach (var property in template.GetProperty("Resources").EnumerateObject()) | ||
| { | ||
| if (property.Value.TryGetProperty("Type", out var resourceType) | ||
| && resourceType.GetString() == type) | ||
| { | ||
| result.Add(new KeyValuePair<string, JsonElement>(property.Name, property.Value)); | ||
| } | ||
| } |
Expose UseLogsEndpointUrl/UseCompanionEndpointUrl outputs from the sandbox app stack and add an explicit signed-invoke step (5c) to the run instructions, so the delivery check (--expect-delivery) has recent events for the Use-mode groups and the service-created uselogs.local companion exists before it runs. Addresses the Codex review finding on samples/web-functions/sandbox/README.md (smoke.sh only drives the Next.js/ASP.NET Core/Blazor endpoints). #104
|
@codex review Follow-up review requested for commit c93c42a, which addresses the single Codex finding from the initial review (P2 on
Please confirm this resolves the finding and does not introduce regressions or leave the original finding unresolved. (The separate Offline sandbox suites remain green after the change: run-scenarios 110 passed/0 failed, run-smoke-scenarios 44 passed/0 failed; the sandbox app stack builds with 0 warnings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c93c42a4af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| curl -sS -o /dev/null --aws-sigv4 "aws:amz:${SANDBOX_REGION}:lambda" \ | ||
| --user "${AK}:${SK}" -H "x-amz-security-token: ${TOKEN}" "$(output "$KEY")" || true |
There was a problem hiding this comment.
Include the required payload-hash header in signed requests
The new invocation step omits x-amz-content-sha256: UNSIGNED-PAYLOAD, which docs/constructs/web-function.md documents as required for IAM-authenticated requests and the existing signer in smoke.sh explicitly supplies. Replaying this new command against a local HTTP listener with curl 8.5.0 confirmed that --aws-sigv4 does not automatically emit that header for service lambda. Consequently, these requests are rejected before reaching either workload, leaving the original fresh-sandbox delivery failure unresolved despite exposing the endpoint URLs. Add the payload-hash header to both requests; discarding their responses currently conceals the authentication failure.
Useful? React with 👍 / 👎.
…ash header The new 5c invocation step in the sandbox README omitted the x-amz-content-sha256: UNSIGNED-PAYLOAD header that IAM-authenticated Web Function endpoints require (documented in docs/constructs/web-function.md and explicitly supplied by smoke.sh's signer). Without it the signed requests are rejected before reaching the workloads, leaving the original fresh-sandbox delivery failure unresolved. Add the header to both requests and surface the HTTP status instead of silently discarding the response. Addresses review finding on #104.
|
@codex review Follow-up review requested for commit 1154205, which addresses the new P2 finding (missing payload-hash header) from the previous review of c93c42a:
Please confirm this resolves the finding and that no remaining actionable findings or regressions exist on this commit. |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Manage the Web Function
.localcompanion log group with finite retention, so a Web Function never leaves an unbounded, untagged log group behind. Synthesizing a Web Function withWebFunctionLogs.Create()now produces twoAWS::Logs::LogGroupresources — the centralized group and its home-Region.localcompanion — both with finite retention and the same removal policy:Create(retention, removalPolicy, companionRetention = 1–7 days)— creates the centralized group and the.localcompanion; the companion has an independently configurable finite retention (default 3 days) and inherits the removal policy.Use(logGroup, companion?)— the documented, tested path to bring your own centralized group and optional companion and avoid an unmanaged companion; grants are scoped to the companion and, when the role is managed by the construct, includelogs:CreateLogGroupon the home-Region companion ARN.ServiceDefault()— documented behavior unchanged (no construct-managed groups).The capability is tracked by GitHub issue #104 and implements approved design revision 5 (
docs/designs/lambda-web-functions-integration.md). It ships as a new2.6.0-preview.Nfrommain; stable2.6.0is not published.Changes
WebFunctionLogsAPI (src/LayeredCraft.Cdk.Constructs/Models/WebFunctionLogs.cs): adds optionalcompanionRetentiontoCreateand an optionalcompaniontoUse, with token-safe validation that a caller-supplied companion is named{centralized}.local.WebFunctionConstruct(src/LayeredCraft.Cdk.Constructs/WebFunctionConstruct.cs): creates the companionLogGroupfor theCreatepath, exposesLocalLogGroup, wires the revision to depend on both groups, and emits the unmanaged-companion warning W1 (@layeredcraft/cdk-constructs:webFunctionUnmanagedCompanionLogGroup) whenUseis called without a companion.WebFunctionEndpointConstruct: emits the remote-companion warning W2 (@layeredcraft/cdk-constructs:webFunctionRemoteCompanionLogGroups) forPerRegion/MultiRegionendpoints, where the companion log group is not created by this stack; the companion write grant uses a region-scoped ARN in that case.docs/constructs/web-function.md,docs/testing/index.md,CLAUDE.md, andCHANGELOG.mdupdated (two groups perCreate,AlreadyExistsremedy, recompile note, CDK floor unchanged).Validation
Local (final release candidate)
dotnet build LayeredCraft.Cdk.Constructs.slnx -c Release→ succeeded, 0 warnings, 0 errors (net8.0–net11.0).dotnet test LayeredCraft.Cdk.Constructs.slnx -c Release --no-build→ 2380 total, 0 failed, 0 skipped (595 tests × 4 TFMs).web-function-cloudfront-oac.json,web-function-default.json,web-function-externally-managed.json,web-function-invoke-grants.json,web-function-multi-endpoint.json,web-function-owned-bucket.json(+10 lines each) and the newweb-function-use-log-group.json(+44 lines).web-function-application-managed.jsonand every non-Web-Function golden (cognito×3, dynamodb×4, lambda×6, static-site×4) are unchanged → existing constructs show zero diff.Live AWS sandbox (bead
cdkc-18e.18.4)Validated in authorized sandbox
wft7d(account403542860824,us-east-1), namespacelccdk-wf-sandbox; all stacksCREATE_COMPLETE;nextjs/aspnetcore/blazor/uselogs/usecompanionfunctions Active.DependsOn.logs filter-log-events, 4h lookback); no extra sandbox group; both centralized and.localdelivered.verify-log-groups.sh --expect-delivery→ PASS=31 FAIL=0 SKIP=0 BLOCKED=0.Use-mode grants (G1/G2)logs:CreateLogStream/PutLogEventson.../uselogs:*and.../uselogs.local:log-stream:*, pluslogs:CreateLogGroupon.../uselogs.local(no:*suffix, G2 ARN form confirmed); group not part of the app stack'sAWS::Logs::LogGroupresources.Usewith an explicit companion yields G1-only grants (noCreateLogGroup), no duplicate group, supplied retentions preserved, delivery confirmed.cdk.outmetadata); W2 SKIPPED (noPerRegion/MultiRegionendpoint deployed in the sandbox).AlreadyExistscollision.../uselogs.localremoved by exact name; post-destroy and delayed (180s) rechecks show no recreation.Offline suites:
run-scenarios110 pass,run-smoke-scenarios44 pass. A sandbox-harness state-isolation defect (SANDBOX_STATE_DIR) was fixed; no production-construct defect was found.Breaking Changes
None at the source level. The added optional parameters on
WebFunctionLogs.Create/Use(design decision D2) are source-compatible. They are binary-incompatible with2.6.0-preview.27: assemblies compiled against the prior preview must be recompiled, otherwise aMissingMethodExceptioncan occur. No released version is claimed by this PR. The CDK floor is unchanged atAmazon.CDK.Lib >= 2.274.0.Related Issues
2.6.0remains blocked on beadcdkc-18e.17and Sharedale #162 validation.Notes for Reviewers
docs/designs/lambda-web-functions-integration.mdare the authoritative record; warnings are referenced verbatim as W1/W2.